import api from './index'
import axios from 'axios'

let loginHeaders = {
  'Content-Type': 'application/json'
}
export default {
  getHeader () {
    return {
      'Content-Type': 'application/json',
      'Authorization': 'Baibai' + localStorage.getItem('token')
    }
  },

  getCompany () {
    return axios.get(api.getCompany(), {params: {currentPage: 1, pageSize: 9}}, {headers: this.getHeader()})
  },
  userRegister (info) {
    return axios.post(api.userRegister(), JSON.stringify(info), {headers: this.getHeader()})
  },
  getComName () {
    return axios.get(api.getComName(), {headers: this.getHeader()})
  },
  userLogin (info) {
    return axios.post(api.userLogin(), JSON.stringify(info), {headers: loginHeaders})
  },
  getUserInfo (userId) {
    return axios.get(api.getUserInfo(userId), {headers: this.getHeader()})
  },
  sendCode (email) {
    return axios.post(api.sendCode(), {email: email}, {headers: this.getHeader()})
  },
  logout () {
    return axios.get(api.logout(), {headers: this.getHeader()})
  },
  sendResume (resumeInfo) {
    return axios.put(api.sendResume(), JSON.stringify(resumeInfo), {headers: this.getHeader()})
  },
  deliveryList (id) {
    return axios.get(api.deliveryList(id), {headers: this.getHeader()})
  },
  putUserInfo (userInfo) {
    return axios.post(api.putUserInfo(), JSON.stringify(userInfo), {headers: this.getHeader()})
  },
  changePhone (phone) {
    return axios.put(api.changePhone(), {mobile: phone}, {headers: this.getHeader()})
  },
  changePass (password) {
    return axios.put(api.changePass(), {oldPassword: password.oldPassword, newPassword: password.newPassword}, {headers: this.getHeader()})
  },
  changeEmail (email) {
    return axios.put(api.changeEmail(), {email: email}, {headers: this.getHeader()})
  },
  getCompanyDetail (id) {
    return axios.get(api.getCompanyDetail(id), {headers: this.getHeader()})
  },
  getResume (userId) {
    return axios.get(api.getResume(), {params: {userId: userId}}, {headers: this.getHeader()})
  },
  getJobDetail (id) {
    return axios.get(api.getJobDetail(id), {headers: this.getHeader()})
  },
  deliveryResume (body) {
    return axios.put(api.deliveryReusme(), JSON.stringify(body), {headers: this.getHeader()})
  },
  getMessage () {
    return axios.get(api.getMessage(), {headers: this.getHeader()})
  },
  findJob (key) {
    return axios.get(api.findJob(key), {headers: this.getHeader()})
  },
  readMessage (info) {
    return axios.post(api.readMessage(), JSON.stringify(info), {headers: this.getHeader()})
  },
  receiveResume (id) {
    return axios.get(api.receiveResume(id), {headers: this.getHeader()})
  },
  publishJob (jobinfo) {
    return axios.put(api.publishJob(), JSON.stringify(jobinfo), {headers: this.getHeader()})
  },
  checkJob (query) {
    return axios.post(api.checkJob(), JSON.stringify(query), {headers: this.getHeader()})
  },
  deletejob (id) {
    return axios.delete(api.deletejob(), {params: {id: id}}, {headers: this.getHeader()})
  },
  hrRegister (hrInfo) {
    return axios.post(api.hrRegister(), JSON.stringify(hrInfo), {headers: this.getHeader()})
  },
  verifyMessage (authCode) {
    return axios.post(api.verifyMessage(), JSON.stringify(authCode), {headers: this.getHeader()})
  },
  recommendCandidate () {
    return axios.get(api.recommendCandidate(), {headers: this.getHeader()})
  },
  recommendJob () {
    return axios.get(api.recommendJob(), {headers: this.getHeader()})
  },
  getRecommandJob () {
    return axios.get(api.getRecommandJob(), {headers: this.getHeader()})
  },
  // 添加公司
  addCompany (companyInfo) {
    return axios.post(api.getCompany(), JSON.stringify(companyInfo), {headers: this.getHeader()})
  },
  // 获取公司
  getCompanyById(id) {
    return axios.get(api.getCompanyById(id), {headers: this.getHeader()})
  },
  // 获取hr
  getHrById(id) {
    return axios.get(api.getHrById(id), {headers: this.getHeader()})
  }
}
